package com.dawn.module.hospital.controller.app.medicalcopy;

import com.dawn.module.hospital.controller.admin.medicalcopy.vo.MedicalCopyPageReqVO;
import com.dawn.module.hospital.controller.admin.medicalcopy.vo.MedicalCopySaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import com.dawn.framework.common.pojo.PageResult;
import com.dawn.framework.common.pojo.CommonResult;
import com.dawn.framework.common.util.object.BeanUtils;
import static com.dawn.framework.common.pojo.CommonResult.success;


import com.dawn.module.hospital.controller.app.medicalcopy.vo.*;
import com.dawn.module.hospital.dal.dataobject.medicalcopy.MedicalCopyDO;
import com.dawn.module.hospital.service.medicalcopy.MedicalCopyService;

@Tag(name = "用户 APP - 病案复印")
@RestController
@RequestMapping("/hospital/medical-copy")
@Validated
public class AppMedicalCopyController {

    @Resource
    private MedicalCopyService medicalCopyService;

    @PostMapping("/create")
    @Operation(summary = "病案复印申请")
    public CommonResult<Long> createMedicalCopy(@Valid @RequestBody MedicalCopySaveReqVO reqVO) {
        return success(medicalCopyService.createMedicalCopy(reqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新病案复印")
    public CommonResult<Boolean> updateMedicalCopy(@Valid @RequestBody MedicalCopySaveReqVO reqVO) {
        medicalCopyService.updateMedicalCopy(reqVO);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除病案复印")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteMedicalCopy(@RequestParam("id") Long id) {
        medicalCopyService.deleteMedicalCopy(id);
        return success(true);
    }

    @PostMapping("/get")
    @Operation(summary = "获得病案复印")
    public CommonResult<AppMedicalCopyRespVO> getMedicalCopy(@Valid @RequestBody AppMedicalCopyPageReqVO reqVO) {
        MedicalCopyPageReqVO pageReqVO = BeanUtils.toBean(reqVO, MedicalCopyPageReqVO.class);
        MedicalCopyDO medicalCopy = medicalCopyService.getMedicalCopy(pageReqVO.getId());
        return success(BeanUtils.toBean(medicalCopy, AppMedicalCopyRespVO.class));
    }

    @PostMapping("/page")
    @Operation(summary = "获得病案复印分页")
    public CommonResult<PageResult<AppMedicalCopyRespVO>> getMedicalCopyPage(@Valid @RequestBody AppMedicalCopyPageReqVO reqVO) {
        MedicalCopyPageReqVO pageReqVO = BeanUtils.toBean(reqVO, MedicalCopyPageReqVO.class);
        PageResult<MedicalCopyDO> pageResult = medicalCopyService.getMedicalCopyPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppMedicalCopyRespVO.class));
    }


}